#include "Logger.h"
#include <sstream>

namespace log
{


Logger::Logger(const std::string& name)
    : m_strName(name)
{

}
    
void Logger::log(LogEvent::ptr ptrEvent)
{
    //static const char spliter = ' ';
    //std::ostringstream os;
    //os << strTime << spliter;
    //os << "[" << LogLevel::toString(eLevel) << "]" << spliter;
    //os << "[" << strFile << ":" << nLine << "]" << spliter;
    //os << "[" << strFunc << "]" << spliter;
    //os << strLog << std::endl;

    utils::LockGuard<utils::Mutex> lock(m_mutex);
    for (auto app : m_vecApps)
    {
        app->append(ptrEvent);
    }
}

void Logger::addAppender(LogAppender::ptr ptrAppend)
{
    utils::LockGuard<utils::Mutex> lock(m_mutex);
    m_vecApps.push_back(ptrAppend);
}

void Logger::setAppender(std::vector<LogAppender::ptr> vecApps)
{
    utils::LockGuard<utils::Mutex> lock(m_mutex);
    m_vecApps = vecApps;
}

std::vector<LogAppender::ptr> Logger::getAppender()
{
    utils::LockGuard<utils::Mutex> lock(m_mutex);
    return m_vecApps;
}

} // namespace log
